package com.xyy.saas.payment.pojo.dto;

import com.xyy.saas.payment.constants.Constants;
import com.xyy.saas.payment.pojo.vo.ReportExportOrderVo;
import com.xyy.saas.payment.pojo.vo.ReportQueryOrderVo;
import com.xyy.saas.payment.util.PageUtil;
import org.apache.commons.lang3.ObjectUtils;

import java.util.Date;

/**
 * @author wangtianqi
 * @date 2020/5/20 14:54
 */
public class ConvertReport {

    public static ReportQueryOrderDto convertReportQueryOrderDto(ReportQueryOrderVo vo) {
        ReportQueryOrderDto reportQueryOrderDto = new ReportQueryOrderDto();
        reportQueryOrderDto.setBeginDate(ObjectUtils.allNotNull(vo.getBeginDate()) ? new Date(vo.getBeginDate()) : null);
        reportQueryOrderDto.setEndDate(ObjectUtils.allNotNull(vo.getEndDate()) ? new Date(vo.getEndDate() + Constants.DATE_FIX) : null);
        reportQueryOrderDto.setBusinessOrderNo(vo.getBusinessOrderNo());
        reportQueryOrderDto.setBusinessOrderType(vo.getBusinessOrderType());
        reportQueryOrderDto.setChannelTransactionNo(vo.getChannelTransactionNo());
        if(vo.getPageSize() == null) {
            vo.setPageSize(Constants.DEFAULT_PAGE_SIZE);
        }
        reportQueryOrderDto.setPage(vo.getPage() == null ? 0 :  PageUtil.getPageOffset(vo.getPage(), vo.getPageSize()));
        reportQueryOrderDto.setPageSize(vo.getPageSize());
        reportQueryOrderDto.setOrderType(vo.getOrderType());
        reportQueryOrderDto.setPayer(vo.getPayer());
        reportQueryOrderDto.setPayMode(vo.getPayMode());
        reportQueryOrderDto.setTradeNo(vo.getTradeNo());
        return reportQueryOrderDto;
    }

    public static ReportQueryOrderDto convertReportQueryOrderDto(ReportExportOrderVo vo, Integer page, Integer pageSize) {
        ReportQueryOrderDto reportQueryOrderDto = new ReportQueryOrderDto();
        reportQueryOrderDto.setBeginDate(ObjectUtils.allNotNull(vo.getBeginDate()) ? new Date(vo.getBeginDate()) : null);
        reportQueryOrderDto.setEndDate(ObjectUtils.allNotNull(vo.getEndDate()) ? new Date(vo.getEndDate() + Constants.DATE_FIX) : null);
        reportQueryOrderDto.setBusinessOrderNo(vo.getBusinessOrderNo());
        reportQueryOrderDto.setBusinessOrderType(vo.getBusinessOrderType());
        reportQueryOrderDto.setChannelTransactionNo(vo.getChannelTransactionNo());
        if(pageSize == null) {
            pageSize = Constants.DEFAULT_PAGE_SIZE;
        }
        reportQueryOrderDto.setPage(page == null ? 0 :  PageUtil.getPageOffset(page, pageSize));
        reportQueryOrderDto.setPageSize(pageSize);
        reportQueryOrderDto.setOrderType(vo.getOrderType());
        reportQueryOrderDto.setPayer(vo.getPayer());
        reportQueryOrderDto.setPayMode(vo.getPayMode());
        reportQueryOrderDto.setTradeNo(vo.getTradeNo());
        return reportQueryOrderDto;
    }


    public static ReportQueryOrderVo convertReportQueryOrderVo(ReportExportOrderVo reportExportOrderVo, int page, int size) {
        ReportQueryOrderVo reportQueryOrderVo = new ReportQueryOrderVo();
        reportQueryOrderVo.setBeginDate(reportExportOrderVo.getBeginDate());
        reportQueryOrderVo.setBusinessOrderNo(reportExportOrderVo.getBusinessOrderNo());
        reportQueryOrderVo.setBusinessOrderType(reportExportOrderVo.getBusinessOrderType());
        reportQueryOrderVo.setEndDate(reportExportOrderVo.getEndDate());
        reportQueryOrderVo.setOrderType(reportExportOrderVo.getOrderType());
        reportQueryOrderVo.setPage(page);
        reportQueryOrderVo.setPageSize(size);
        reportQueryOrderVo.setPayer(reportExportOrderVo.getPayer());
        reportQueryOrderVo.setPayMode(reportExportOrderVo.getPayMode());
        reportQueryOrderVo.setTradeNo(reportExportOrderVo.getTradeNo());
        reportQueryOrderVo.setChannelTransactionNo(reportExportOrderVo.getChannelTransactionNo());
        return reportQueryOrderVo;
    }



}
